# arica-service docker配置
FROM openjdk:8

# 指定维护者信息
MAINTAINER soo (807966224@qq.com)

# 指定挂载目录
VOLUME /tmp

# 指令指定一个环境变量
ENV PROJECT_HOME /home/project
ENV TOMCAT_HOME /home/tomcat/webapps
ENV OUTPUT_HOME /output

RUN mkdir -p "$PROJECT_HOME" && mkdir -p "$OUTPUT_HOME" && mkdir -p "$TOMCAT_HOME"

ADD arica-service.jar /home/project/arica-service.jar

WORKDIR /home/project

# 指定容器内的时区
RUN echo "Asia/Shanghai" > /etc/timezone

# 更新文件时间戳
RUN sh -c 'touch  /home/project/arica-service.jar'

# 非阻塞模式加快启动jar速度
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /home/project/arica-service.jar > $OUTPUT_HOME/service.log" ]

EXPOSE 8181


# 将Dockerfile、jar文件上传至服务器；执行：docker build -t soo/service:1.0 .
# REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
# soo/service                     1.0                 de2ae6654e6a        13 seconds ago      475MB
# 默认运行本地开发环境(application-dev.yml)
# docker run --cap-add=SYS_PTRACE --ulimit core=-1 -it -d --name arica-service -p8181:8181 -m=512M --memory-swap=128M -e JAVA_OPTS='-Dspring.profiles.active=dev -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMPercentage=80.0 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/data/logs/' --network=test-net -v /output:/output -v /home/tomcat/webapps:/home/tomcat/webapps soo/service:1.0
# 预发布环境
# docker run --cap-add=SYS_PTRACE --ulimit core=-1 -it -d --name arica-service -p8181:8181 -m=512M --memory-swap=128M -e JAVA_OPTS='-Dspring.profiles.active=pre -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMPercentage=80.0 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/data/logs/' --network=test-net  -v /output:/output -v /home/tomcat/webapps:/home/tomcat/webapps soo/service:1.0
# 生产环境
# docker run --cap-add=SYS_PTRACE --ulimit core=-1 -it -d --name arica-service -p8181:8181 -m=512M --memory-swap=128M -e JAVA_OPTS='-Dspring.profiles.active=product -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMPercentage=80.0 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/data/logs/' --network=test-net  -v /output:/output -v /home/tomcat/webapps:/home/tomcat/webapps soo/service:1.0